//
//  HomePageNavBar.m
//  ZhiHuDaily
//
//  Created by 吴宜昊 on 2022/2/6.
//

#import "HomePageNavBar.h"


@interface HomePageNavBar ()
@property(nonatomic,strong) UILabel * labelDate;
@property(nonatomic,strong) UIView * splitView;
@property(nonatomic,strong) UILabel * labelTitle;
@end
@implementation HomePageNavBar

#pragma mark - override
-(instancetype) initWithFrame:(CGRect) frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

-(void) updateConstraints {
    [self remakeMas];
    [super updateConstraints];
}

#pragma mark - remakeMas
-(void) remakeMas {
    WeakSelf(self);
    [self.labelDate mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@16);
        make.top.equalTo(@(kStatusBarHeight));
        make.bottom.equalTo(@0);
    }];
    
    [self.splitView mas_remakeConstraints:^(MASConstraintMaker *make) {
        StrongSelf(weakSelf);
        make.left.equalTo(strongSelf.labelDate.mas_right).offset(16);
        make.height.equalTo(@22);
        make.width.equalTo(@1);
        make.centerY.equalTo(strongSelf.labelDate);
    }];
    
    [self.labelTitle mas_remakeConstraints:^(MASConstraintMaker *make) {
        StrongSelf(weakSelf);
        make.left.equalTo(strongSelf.splitView.mas_right).offset(16);
        make.centerY.equalTo(strongSelf.labelDate);
    }];
}

#pragma mark - override
-(void) setupUI {
    
    [self addSubview:self.labelDate];
    [self addSubview:self.splitView];
    [self addSubview:self.labelTitle];
    [self setNeedsUpdateConstraints];
}

#pragma mark - lazy
-(UILabel *) labelDate {
    if (!_labelDate) {
        _labelDate = [UILabel new];
        _labelDate.font = FontPingFangMedium(14);
        _labelDate.textColor = RGB(83, 84, 231);
        _labelDate.text = @"     ";
    }
    return _labelDate;
}

-(UIView *) splitView {
    if (!_splitView) {
        _splitView = [UIView new];
        _splitView.backgroundColor = HEXCOLOR(0xA8A8A8);
    }
    return _splitView;
}

-(UILabel *) labelTitle {
    if (!_labelTitle) {
        _labelTitle = [UILabel new];
        _labelTitle.font = FontPingFangMedium(22);
        _labelTitle.textColor = UIColor.blackColor;
        _labelTitle.numberOfLines = 2;
        _labelTitle.text = @"知乎日报";
    }
    return _labelTitle;
}

#pragma mark - OPEN API
-(void) updateDate:(DateModel *) model {
    
    self.labelDate.text = [NSString stringWithFormat:@"%02ld月%02ld日",model.month ,model.day];
}

@end
